package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("strategyComments")
public class StrategyCommentController {
    @Autowired
    private IStrategyCommentService commentService;

   /* @GetMapping
    public List<StrategyComment> list(){
        return commentService.selelctStrategyByState();
    }*/


    @GetMapping(value = "/{strategyId}/b")
    public List<StrategyComment> selectByStrategyId(@PathVariable("strategyId") Long strategyId){
        return commentService.selectByStrategyId(strategyId);
    }
    @GetMapping(value = "/{id}/a")
    public StrategyComment selectBystrategyCommentId(@PathVariable("id") Long id){
        return commentService.selectBystrategyCommentId(id);
    }

    @PostMapping("/save")
    JsonResult save(StrategyComment comment){
        JsonResult result = new JsonResult();
        try {
            commentService.save(comment);


        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    @GetMapping("/users/{userId}")
    public List<StrategyComment> selectByUserId(@PathVariable Long userId){
        return commentService.selectByUserId(userId);
    }

    @GetMapping("/{strategyId}/comments")
    List<StrategyComment> listByStrategyId(@PathVariable Long strategyId){
        return commentService.listByStrategyId(strategyId);
    }
    @GetMapping("/{id}")
    public StrategyComment getById(@PathVariable("id") Long id) {

        return commentService.getById(id);
    }

    //头条点评查询十条最新推荐
    @GetMapping
    public PageInfo queryForList(StrategyCommentQueryObject qo){
        qo.setOrderBy("sc.commendTime desc");
        qo.setState(1);
        PageInfo<StrategyComment> result = commentService.queryForLists(qo);
        return result;
    }


    @GetMapping("/{userId}/commends")
    public PageInfo getStrategyCommentById(StrategyCommentQueryObject qo){
        PageInfo<StrategyComment> result = commentService.getStrategyCommentById(qo);
        return result;
    }
}
